#!/bin/bash
echo "正在检查系统是否更新..."
if [ $? -eq 0 ]; then
    echo "系统已更新"
else
    apt update && apt upgrade -y
    echo "开始更新"
fi

if grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
    echo "系统为ubuntu"
    else
        echo "请在Ubuntu容器内打开和使用此脚本"
        exit 1
fi

if [ "$(whoami)" != "root" ]; then
    sudo -i
fi

if [ -d "$HOME/Miao-Yunzai" ]; then
    lsy="$HOME/Miao-Yunzai"
    jh="$HOME/Miao-Yunzai/plugins"
    xrk="$HOME/xrk"
elif [ -d "$HOME/Yunzai-Bot" ]; then
    lsy="$HOME/Yunzai-Bot"
    jh="$HOME/Yunzai-Bot/plugins"
    xrk="$HOME/xrk"
elif [ -d "$HOME/yxybot" ]; then
    lsy="$HOME/yxybot"
    jh="$HOME/yxybot/plugins"
    xrk="$HOME/xrk"
else
    echo "您未安装机器人,记得通过脚本安装机器人哦"
fi

if [ ! -d "$lsy/node_modules/icqq" ] && [ -d "$HOME/Yunzai-Bot" ]; then
    echo "没有icqq依赖"
    cd Yunzai-Bot                 
        git remote set-url origin https://gitee.com/yoimiya-kokomi/Yunzai-Bot.git && git checkout main && git pull
        git reset --hard origin/main
        pnpm install -P
        pnpm install pm2 -g
        pm2 update
        pnpm i
        cd $HOME
    echo "换源成功"
fi

if [ -d "$HOME/Miao-Yunzai" ] && [ -d "$jh/qianyu-plugin" ]; then
    rm -rf $lsy/plugins/qianyu-plugin
fi

current_time=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "\e[1;36m现在的时间是 : $current_time\e[0m"
function show_menu
{
echo -e "\e[1;32m╭────────────────────────────────────────────╮\e[0m"
echo -e "\e[1;32m│               向日葵安装脚本               │\e[0m"
echo -e "\e[1;32m│  https://gitee.com/xrk114514/shell-Yunzai  │\e[0m"
echo -e "\e[1;32m├─────────────────────┬──────────────────────┤\e[0m"
echo -e "\e[1;36m│    工作室674752705  │    答疑群279071460   │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  1 安装云崽         │ 2 安装插件(含ffmpeg) │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  3 安装js插件       │ 4 重启指令失效的问题 │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  5 浏览器修复       │ 6 登录错误           │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  7 写入云崽启动命令 │ 8 更新日志           │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  9 向日葵密钥菜单   │ 10 向日葵贱贱动画    │\e[0m"
echo -e "\e[1;32m╰─────────────────────┴──────────────────────╯\e[0m"
}
echo -e "\e[1;32m向日葵祝您生活美好，事事顺利\e[0m"
cat <<xrk
╭─────────────────────────────────────────────────────────────────────╮
│ 当前脚本版本为v2.0.1，脚本已写入本地，最大限度的提供运算速度与便利  │
│ ○○○●●● 如果要更新请输入r                                            │
╰─────────────────────────────────────────────────────────────────────╯
xrk
while [ 1 ]
do
    show_menu
    read -p "请从四个选项中选一个: " CHOICE

    case "$CHOICE" in
        1 )
            echo "向日葵qq1814632762"
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-yz/yz.sh)
            exit 1
            ;;
        2 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-all/plu.sh)
            ;;
        3 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-all/js.sh)
            ;;
        4 )
            if [ -d "$lsy" ]; then
            echo "正在修复重启命令失败问题"
            rm -rf $HOME/.pm2 $lsy/node_modules
            cd $lsy && pnpm i
            echo "成功，请输入yz打开云崽吧！"
               else
                   echo "请先安装云崽啊喂"
            fi
            ;;
        5 )
            echo "此方法如今不知道能不能用"
            apt-get install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y
            exit 1
            ;;
        6 ) 
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-version-issue/bbgd.sh)
            ;;
        7 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-yz/yzxz.sh)
            ;;
        8 ) 
            echo "
            最近更新了本地脚本写入，并且优化了很多细节，
            并且最近在建设密钥的措施，准备加一些精华插件
            "
            ;;
        9 ) 
            if [ condition1 ]; then
                defmy="32077c2bb398aa61a5f3bc3c67871e00"
            elif [ condition2 ]; then
                defmy="c2c159da4767349dc98c016b4317bea0"
                else
                    defmy="04304c10452477944c3d30b2e5af13bb"
            fi
            read -p "请输入密钥：" my
            usermy=$(echo "$my" | md5sum | cut -d' ' -f1)
            if [ "$usermy" = "$defmy" ]; then
                echo "密钥"$my"正确"
                else
                    echo "密钥"$my"不正确"
            fi
            ;;
        10 )
height=10
width=40
x=5
y=5
score=0
generate_bean() {
  bean_x=$((RANDOM%height+2))
  bean_y=$((RANDOM%width+2))
}
generate_bean
draw_board() {
  clear
  printf "欢迎来到吃向日葵比赛现场
  "
  printf "输入6可以退出游戏*
  "
  printf "w向上s向下a向左b向右
  "
  printf "目前分数: $score\n\n"
  for ((i=1;i<=$height;i++)); do
    for ((j=1;j<=$width;j++)); do
      if [ $i -eq 1 -o $i -eq $height -o $j -eq 1 -o $j -eq $width ]; then
        printf "#"
      elif [ $i -eq $x -a $j -eq $y ]; then
        printf "😍"
      elif [ $i -eq $bean_x -a $j -eq $bean_y ]; then
        printf "🌻"
      else
        printf " "
      fi
    done
    printf "\n"
  done
}
move() {
  read -s -n 1 key
  case "$key" in
    "a") ((y--));;
    "d") ((y++));;
    "s") ((x++));;
    "w") ((x--));;
    "6") exit;;
    *) ;;
  esac
}
while true; do
  draw_board
  move
  if [ $x -eq $bean_x -a $y -eq $bean_y ]; then
    ((score++))
    generate_bean
  fi
done
            ;;
         r )
             echo "$(curl -sL https://gitee.com/xrk114514/shell-Yunzai/raw/master/xrk)" > /usr/local/bin/xrk && chmod 755 /usr/local/bin/xrk && echo "更新完成，为您退出" || echo "更新失败"
             exit 1
            ;;
         * )
             echo "让你乱点，给你退了"
             exit 1
            ;;
    esac
done